// components/car-input/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    currentItem: {
      type: Number,
      value: 0,
      observer: 'changeKeyBoard'
    },
    carNumber: {
      type: String,
      value: '',
      observer: 'numberToArray'
    },
    keyBoardType: {
      type: Number,
      value: 1
    },
    isShow:Boolean
  },

  /**
   * 组件的初始数据
   */
  data: {
    carArray: ['', '', '', '', '', '', '']
  },

  /**
   * 组件的方法列表
   */
  methods: {
    numberToArray(v = this.data.carNumber) {
      console.log('numberToArray', v)
      if(v){
        this.setData({
          'carArray[0]': v[0],
          'carArray[1]': v[1],
          'carArray[2]': v[2],
          'carArray[3]': v[3],
          'carArray[4]': v[4],
          'carArray[5]': v[5],
          'carArray[6]': v[6]
        })
      }else{
        this.setData({
          carArray: ['', '', '', '', '', '', ''],
          currentItem:0
        })
      }
      console.log('carArray:', this.data.carArray)
    },
    changeKeyBoard(v){
      let keyBoardType=0
      if (v == 0) {keyBoardType= 1 } 
      else if (v == 1) {keyBoardType=2} 
      else { keyBoardType= 3}
      this.setData({
        keyBoardType: keyBoardType
      })
    },
    handleClickCarInputItem(e) {
      let index = e.currentTarget.id
      this.setData({
        currentItem: index,
      })
    },
    inputchange({detail}) {
      let index = this.data.currentItem
      this.setData({
        [`carArray[${index}]`]: detail,
        currentItem: this.data.currentItem == 6 ? this.data.currentItem:this.data.currentItem+1
      })
    },
    colseCarInput(){
      this.setData({
        isShow:false
      })
      this.numberToArray()
    },
    submitCarInput() {
      let str = this.data.carArray.join('')
      console.log(str)
      this.setData({
        isShow: false,
        currentItem:0
      })
      this.triggerEvent('submit',str);
    },

  }
})